package com.dundun.SSO.controller.manage;

import com.dundun.SSO.core.base.BaseController;
import com.dundun.SSO.manage.ISsoUserAccountService;
import com.dundun.SSO.manage.ISsoUserService;
import com.dundun.SSO.manage.pojo.SsoGroup;
import com.dundun.SSO.manage.pojo.SsoUser;
import com.dundun.SSO.manage.pojo.SsoUserAccount;
import com.dundun.SSO.pojo.ResponseBean;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**********************************************************
 * 版权所有：搜影科技 保留所有权利
 * 创建日期: 2017/5/15 0015 16:42
 * 创建作者: gezhangkai
 * 版    本:
 * 功    能:
 * 最后修改时间:
 * 修改记录:
 ***********************************************************/
public class LoginController extends BaseController{
    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ISsoUserAccountService ssoUserAccountService;

    @Autowired
    private ISsoUserService ssoUserService;

    @RequestMapping("/login.html")
    public String getPage(HttpServletRequest request,@RequestBody String url){
        request.setAttribute("url",url);
        return "/manage/login";
    }

    @RequestMapping("login")
    public ResponseBean login(HttpServletRequest request,@RequestBody SsoUserAccount ssoUserAccount) {
        if(StringUtils.isBlank(ssoUserAccount.getAccount()) || StringUtils.isBlank(ssoUserAccount.getPassword())){

        }
        SsoUserAccount ssoUserAccount1 = new SsoUserAccount();
        ssoUserAccount1.setAccount(ssoUserAccount.getAccount());
        ssoUserAccount1 = ssoUserAccountService.selectOne(ssoUserAccount1);
        if(ssoUserAccount1.getPassword().equals(ssoUserAccount.getPassword())){
            SsoUser ssoUser = new SsoUser();
            ssoUser.setAccount(ssoUserAccount.getAccount());
            ssoUser = ssoUserService.selectOne(ssoUser);
            request.getSession().setAttribute("user",ssoUser);
            return ResponseBean.success(null,null);
        }else{
            return ResponseBean.parameterError("账号或密码错误");
        }
    }
}
